/*
 * Block Class
 * 
 * Represents a block of track of a Line
 * 
 */
package Track.Track;

/**
 *
 * @author Chris
 */
public class Block {
    
    //All information realting to a block of track including Stations and Railway Crossings
    protected int id;
    private double slope;
    private double MaxSpeedLimit;
    private double CTCRequestedSpeedLimit;
    private double TrackControllerSetSpeedLimit;
    private int ControllerAuthority;
    private int CTCAuthority;
    double length;
    Block nextBlock;
    Block previousBlock;
    boolean bidirectional;
    boolean isUnderground;
    double xVal;
    double yVal;
    boolean trackCircuitBroken;
    public int signalState;
    public Station blockStation;
    public RailwayCrossing Crossing;
    protected boolean hasCrossing;
    protected boolean hasStation;
    
    //used for testing only
    public boolean brokenRail;
    
    //Constructor method. This system does not currently support x and y coordinates for blocks
    public Block(int idVal, double slop, double max, double len, boolean bidirection, boolean under/*, double x, double y*/){
        id = idVal;
        slope = slop;
        MaxSpeedLimit = max;
        bidirectional = bidirection;
        length = len;
        isUnderground = under;
        trackCircuitBroken = false;
        signalState = 1;
        hasCrossing = false;
        hasStation = false;
        brokenRail = false;
        /*xVal = x;
         * yVal = y;
         */
    }
    
    protected void setNext(Block Next){
        nextBlock = Next;
    }
    protected void setPrevious(Block Previous){
        previousBlock = Previous;
    }
    //Update all information relating to a track controller using a controllerInterface as an input
    protected void updateBlock(ControllerInterface CI){
        this.CTCRequestedSpeedLimit = CI.CTCRequestedSpeedLimit;
        this.TrackControllerSetSpeedLimit = CI.TrackControllerSetSpeedLimit;
        this.ControllerAuthority = CI.ControllerAuthority;
        this.CTCAuthority = CI.CTCAuthority;
        this.trackCircuitBroken = CI.TrackCircuitValue;
    }
    
    //Create and return a ControllerInterface 
    protected ControllerInterface getControllerInterface(){
        ControllerInterface CI = new ControllerInterface(this.MaxSpeedLimit, this.CTCRequestedSpeedLimit, this.TrackControllerSetSpeedLimit, this.ControllerAuthority, this.CTCAuthority, this.trackCircuitBroken);
        return CI;
    }
    //Create and Return a RailInterface
    protected RailInterface getRailInterface(){
        RailInterface RI = new RailInterface(this.TrackControllerSetSpeedLimit, this.ControllerAuthority, this.length, this.slope, this.isUnderground, this.id);
        return RI;
    }    
    //Create a Station
    protected void addStation(String name){
        this.blockStation = new Station(name);
        hasStation = true;
    }
    //Create a Crossing
    protected void addCrossing(){
        this.Crossing = new RailwayCrossing();
        hasCrossing = true;
    }
}